package com.mUI;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.xike.kyt.R;

public class MyDialog extends AlertDialog {

	Context context;
	Button btn_left;
	Button btn_right;
	TextView tv_message;
	TextView tv_title;

	public MyDialog(Context context) {
		super(context);
		this.context = context;
	}

	public MyDialog(Context context, int theme) {
		super(context, theme);
		this.context = context;

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.ui_mydialog);
		btn_left = (Button) findViewById(R.id.mydialog_btn_cancle);
		btn_right = (Button) findViewById(R.id.mydialog_btn_ok);
		tv_message = (TextView) findViewById(R.id.mydialog_tv_message);
		tv_title = (TextView) findViewById(R.id.mydialog_tv_title);
	}

	public void setMessage(String message) {
		if (message != null && !message.equals("")) {
			tv_message.setVisibility(View.VISIBLE);
			tv_message.setTextColor(Color.parseColor("#888888"));
			tv_message.setText(message);
		} else {
			tv_message.setVisibility(View.GONE);
		}

	}

	public void setMessageGrivaty(int gravity) {
		tv_message.setGravity(gravity);
	}

	public void setMessagePadding(int left, int top, int right, int bottom) {
		tv_message.setPadding(left, top, right, bottom);
	}

	public void setTitle(String message) {
		if (message.length() > 10) {
			tv_title.setTextSize(context.getResources().getDimension(15));
		}
		tv_title.setText(message);
	}

	public void setTitleTextColor(String colorRGB) {
		tv_title.setTextColor(Color.parseColor(colorRGB));
	}

	public void setOnBtnRightClickListener(String tag, View.OnClickListener listener) {

		if ("".equals(tag)) {
			btn_right.setVisibility(View.GONE);
		} else {
			btn_right.setVisibility(View.VISIBLE);
			btn_right.setText(tag);
			btn_right.setOnClickListener(listener);
		}
	}

	public void setOnBtnLeftClickListener(String tag, View.OnClickListener listener) {
		if ("".equals(tag)) {
			btn_left.setVisibility(View.GONE);
			if (btn_right.getVisibility() == View.VISIBLE) {
				android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) btn_right.getLayoutParams();
				params.rightMargin = 0;
				btn_right.setLayoutParams(params);
			}
		} else {
			btn_left.setVisibility(View.VISIBLE);
			btn_left.setText(tag);
			btn_left.setOnClickListener(listener);
		}
	}

}
